package com.noah.controller;

import com.noah.pojo.Student;
import com.noah.service.StudentService;

import java.util.ArrayList;
/**
 * @author linchaoran
 */
public class StudentController {
    private StudentService studentService = new StudentService();

    public void add() {
        boolean result = studentService.add();
        if (result){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    public void findAll(){
        ArrayList<Student> list = studentService.findAll();
        if (list.size()==0){
            System.out.println("暂无信息，请添加后再试");
            return;
        }
        System.out.println("学号\t\t姓名\t\t年龄\t\t地址");
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu);
        }
    }

    public void del(String id){
        //检查id是否存在
        boolean exist = studentService.isExist(id);
        if (exist){
            studentService.del(id);
        }else {
            System.out.println("学号不存在，请重新输入");
        }
    }

    public void update(String id){
        //检查id是否存在
        boolean exist = studentService.isExist(id);
        if (exist){
            studentService.update(id);
        }else {
            System.out.println("学号不存在，请重新输入");
        }

    }
}
